package com.v3admin.system.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.v3admin.common.domain.BaseEntity;
import com.v3admin.common.enums.SystemMenuTypeEnum;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 系统菜单
 *
 * @author Junpeng.Li
 * @date 2023-12-15 16:02
 */
@Getter
@Setter
@TableName("system_menu")
public class SystemMenu extends BaseEntity {

    /**
     * 顶级菜单的Pid
     */
    public static final Long TOP_PID = -1L;

    /**
     * 数据库字段
     */
    public static final String TBF_ORDER = "`order`";
    public static final String TBF_ENABLE = "`enable`";
    public static final String TBF_PID = "pid";

    /**
     * 菜单ID
     */
    @TableId(type = IdType.AUTO)
    private Long id;

    /**
     * 父级菜单ID，-1表示顶级菜单, 默认值 = {@link #TOP_PID}
     */
    private Long pid;

    /**
     * 菜单名称
     */
    @NotEmpty(message = "菜单名称不能为空")
    @Length(max = 60, message = "菜单名称只允许输入 1 ~ 60 个字符")
    private String name;

    /**
     * 菜单类型
     */
    @NotNull(message = "菜单类型不能为空")
    private SystemMenuTypeEnum type;

    /**
     * 排序序号
     */
    @TableField(TBF_ORDER)
    private Integer order;

    /**
     * 权限标识
     */
    private String permissionIdent;

    /**
     * 路由地址
     */
    private String routerPath;

    /**
     * 组件路径(vue的component路径)
     */
    private String component;

    /**
     * 外部链接的URL
     */
    private String outlinkUrl;

    /**
     * icon name
     */
    private String icon;

    /**
     * 是否启用
     */
    @TableField(TBF_ENABLE)
    private Boolean enable;

    /**
     * 是否在新标签页打开
     */
    private Boolean newTabOpen;

    /**
     * 描述
     */
    @Length(max = 200, message = "描述信息最多可输入 200 个字符")
    private String description;

    /**
     * 子菜单
     */
    @TableField(exist = false)
    private List<SystemMenu> children;
}
